<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="手机号">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="年龄">
        <el-input v-model="form.age"></el-input>
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="form.address"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即更新</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "jiben",
  data() {
    return {
      id: 1,
      form: {
        phone: '',
        name: '',
        age: '',
        address: '',
      }
    }
  },
  mounted() {
    this.getdata()
  },
  methods: {
    async onSubmit() {
      console.log('submit!');
      const res = await this.$http.patch('ziliao/'+this.id+ "/",this.form)
      if(res.status==200){
        this.$message.success("更新成功")
      }
    },
    async getdata(){
      const res = await this.$http.get('ziliao/', {
            params: {
              "token": window.localStorage.getItem("token")
            }
          }
      )
      console.log(res.data)
      this.form.phone = res.data[0].phone
      this.form.age = res.data[0].age
      this.form.name = res.data[0].name
      this.form.address = res.data[0].address
      this.id = res.data[0].id
      // this.tableData = res.data
    },
  }
}
</script>

<style scoped>

</style>
